package com.csxh.web.service.eshop;

import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.csxh.web.dao.IDao;
import com.csxh.web.dao.eshop.CustomerDao;
import com.csxh.web.mapper.eshop.CustomerMapper;
import com.csxh.web.model.eshop.Customer;
import com.csxh.web.model.eshop.CustomerCondition;
import com.csxh.web.model.mybatis.Condition.RelationOp;
import com.csxh.web.service.PagerService;

@Service
public class CustomerService extends PagerService<Customer> {

	
private CustomerDao thisDao;
	
	@Autowired
	public void setDao(IDao<Customer> dao) {

		this.thisDao= (CustomerDao) dao;
		
		super.setDao(dao);
	}

	
	
public Customer findBy(String username,String password){
		
		SqlSession session = this.thisDao.getSessionFactory().openSession();
		CustomerMapper mapper = session.getMapper(CustomerMapper.class);
		CustomerCondition condition = new CustomerCondition();
		condition.setWhere("username",RelationOp.EQ,username);
		condition.setOffset(0);
		condition.setLimit(1);
		Customer customer=mapper.selectOneByCondition(condition);
		
		if(customer!=null && password.equals(customer.getPassword())){
			return customer;
		}else{
			return null;
		}
		
	}
}
